#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/12/1 16:38
# @Author  : Crissu
# @Site    : 
# @File    : cropPic.py
# @Software: PyCharm
import cv2


imgPath = "./pic.png"
img = cv2.imread(imgPath)
w, h, _ = img.shape
print(w, h)
blockSize = (3, 3)  # 0：长，1：宽
wInterval, hInterval = h / blockSize[1], w / blockSize[0]
wInterval, hInterval = int(wInterval), int(hInterval)
print(wInterval, hInterval)

crop1 = img[0:wInterval, 0:hInterval]
cv2.imwrite("./c1.png", crop1)
crop2 = img[0:wInterval, hInterval:2*hInterval]
cv2.imwrite("./c2.png", crop2)
crop3 = img[0:wInterval, 2*hInterval:3*hInterval]
cv2.imwrite("./c3.png", crop3)

crop4 = img[wInterval:2*wInterval, 0:hInterval]
cv2.imwrite("./c4.png", crop4)
crop5 = img[wInterval:2*wInterval, hInterval:2*hInterval]
cv2.imwrite("./c5.png", crop5)
crop6 = img[wInterval:2*wInterval, 2*hInterval:3*hInterval]
cv2.imwrite("./c6.png", crop6)

crop7 = img[2*wInterval:3*wInterval, 0:hInterval]
cv2.imwrite("./c7.png", crop7)
crop8 = img[2*wInterval:3*wInterval, hInterval:2*hInterval]
cv2.imwrite("./c8.png", crop8)
crop9 = img[2*wInterval:3*wInterval, 2*hInterval:3*hInterval]
cv2.imwrite("./c9.png", crop9)